//--------------------Sonic CD UFO Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
private alias Object.Value0 : Object.ZPos
private alias Object.Value1 : Object.XVelocity
private alias Object.Value2 : Object.ZVelocity
private alias Object.Value3 : Object.Timer
private alias Object.Value4 : Object.ScreenXPos // Difference from the center of the camera (which is where Sonic is always located)
private alias Object.Value5 : Object.ScreenDepth
private alias Object.Value6 : Object.PositionZ
private alias Object.Value7 : Object.BoredTimer


private alias Object.Value8 : Player.SpeedAdjust1
private alias Object.Value9 : Player.SpeedAdjustCap
private alias Object.Value10 : Player.SpeedAdjust3

private alias Object.Value11 : Slender.Health
private alias Object.Value12 : Slender.HalfHP

private alias Object.Value13 : Object.SpawnTimer

private alias Object.Value14 : Object.Shield

private alias object[4].value4 : Crafting.State

// SFX Aliases
private alias 1 : SFX_G_RING

// Priority
private alias 1 : PRIORITY_ACTIVE


public value BossActive = 0;
public value ShieldActive = 0;
public value NextAttack = 0;

public value SlenderSpared = 0;
public value Delta_Activate = 0;

// States
private alias 0 : SLENDERHUNT
private alias 1 : SLENDERVANISH
private alias 2 : SLENDERPREBOSS
private alias 3 : SLENDERBOSSBUILDUP
private alias 4 : SLENDERBOSS_MOVE
private alias 5 : SLENDERBOSS_CREATEPLASMA
private alias 6 : SLENDERBOSS_HITRECOVER
private alias 7 : SLENDERBOSS_LIGHTING
private alias 20 : SLENDERBOSS_DEFEATED
private alias 21 : SLENDERBOSS_DEFEATWAIT
private alias 22 : SLENDERBOSS_WAITFORINPUT
private alias 23 : SLENDERBOSS_DYING

event ObjectMain

	CheckEqual(object[2].state, 13)
	temp5 = checkResult
	CheckEqual(PlayerDied, 1)
	temp5 |= checkResult
	if temp5 == 1
		object.type = TypeName[Blank Object]
	end if
	
	// Check player interaction in this (rather lengthy) process
	
	// X difference
	temp0 = Object.XPos
	temp0 -= TileLayer[0].XPos
	temp0 >>= 8
	
	// Z mutliplier
	temp1 = Object.ZPos
	temp1 -= TileLayer[0].ZPos
	temp1 >>= 8
	
	// Calculating the X difference
	Sin(temp2, TileLayer[0].Angle)
	temp2 *= temp1
	Cos(temp3, TileLayer[0].Angle)
	temp3 *= temp0
	Object.ScreenXPos = temp2
	Object.ScreenXPos -= temp3
	Object.ScreenXPos >>= 9
	
	// Calculating the Z difference
	Cos(temp2, TileLayer[0].Angle)
	temp2 *= temp1
	Sin(temp3, TileLayer[0].Angle)
	temp3 *= temp0
	Object.ScreenDepth = temp2
	Object.ScreenDepth += temp3
	Object.ScreenDepth >>= 9
	
	//hunting code


switch object.state
case SLENDERHUNT	//Page Collecting
if Object[4].Value0 != 0
	//title card gone?
	if Object[20].Type == TypeName[Blank Object]	

	Object.XPos += Object.XVelocity
	Object.ZPos += Object.ZVelocity
	Object.YPos += Object.Yvel

	// Long list of checks for the hitbox detection

	
	// The Player has to be more than 54 pixels off the ground, but lower than 122 pixels towards the sky
	foreach (TypeName[Sonic], arrayPos2, ALL_ENTITIES)	

		//if player isnt hurt
		if object[2].value13 == 0
		// private alias Object.Value8 : Player.SpeedAdjust1
		// private alias Object.Value9 : Player.SpeedAdjust2
		// private alias Object.Value10 : Player.SpeedAdjust3

				switch stage.playerlistpos
				case 0	//norm
					Player.SpeedAdjust1 = 0x2800
					Player.SpeedAdjustCap = 0x22000
					Player.SpeedAdjust3 = 0x1500
				break
				case 1	//easy
					Player.SpeedAdjust1 = 0x2600
					Player.SpeedAdjustCap = 0x18000
					Player.SpeedAdjust3 = 0x1600
				break
				case 2	//hard
					Player.SpeedAdjust1 = 0x3200
					Player.SpeedAdjustCap = 0x26000
					Player.SpeedAdjust3 = 0x1400
				break			
				case 5
					Player.SpeedAdjust1 = 0x3400
					Player.SpeedAdjustCap = 0x28000
					Player.SpeedAdjust3 = 0x1400
				break				
				end switch


				CheckGreater(object.xpos, object[arrayPos2].xpos)
				temp0 = checkResult
				if temp0 == 1		//right
					if Object.XVelocity > 0
						Object.XVelocity -= Player.SpeedAdjust1	//right
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if
					else
						Object.XVelocity -= Player.SpeedAdjust3	//left?? i have no clue
						if Object.XVelocity > Player.SpeedAdjustCap
							Object.XVelocity = Player.SpeedAdjustCap
						end if			
					end if
				else	//left
					if Object.XVelocity < 0
						Object.XVelocity += Player.SpeedAdjust1
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if		
					else
						Object.XVelocity += Player.SpeedAdjust3
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if								
					end if
				end if

				CheckGreater(object.ZPos, object[arrayPos2].Value0)
				temp0 = checkResult
				if temp0 == 1		//right
					if Object.ZVelocity > 0
						Object.ZVelocity -= Player.SpeedAdjust1	//right
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if
					else
						Object.ZVelocity -= Player.SpeedAdjust3	//left?? i have no clue
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if			
					end if
				else	//left
					if Object.ZVelocity < 0
						Object.ZVelocity += Player.SpeedAdjust1
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if		
					else
						Object.ZVelocity += Player.SpeedAdjust3
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if								
					end if
				end if
		else

			Object.ZVelocity = 0
			Object.XVelocity = 0

		
		end if

		
		// The UFO has to be within the 2100 range from the player, who's at a depth of 0x5800 normally
		if Object.ScreenDepth < 0x8C8
			if Object.ScreenDepth > 0x094

				// The UFO has to be between -0.125 and +0.125 pixels away from the screen centre
				if Object.ScreenXPos > -0x2000
					if Object.ScreenXPos < 0x2000

						if object[2].value13 <= 0
							object[2].state = 14
						end if

					end if
				end if
			end if
		end if
	next

	end if
else
	object.state++
end if
break
case SLENDERVANISH	//blank
	if crafting.state >= 7
		object.state++
	end if
break
case SLENDERPREBOSS	//boss start up
	BossActive = 1
	//force position

	temp0 = 1984	//sonlvl positions work
	temp0 <<= 16
	Abs(temp0)

	Object.XPos = temp0

	temp1 = 2112	//sonlvl positions work
	temp1 <<= 16
	Abs(temp1)

	Object.ZPos = temp1


		// The UFO has to be within the 2100 range from the player, who's at a depth of 0x5800 normally
		if Object.ScreenDepth < 0x18C8
			if Object.ScreenDepth > 0x1094

				// The UFO has to be between -0.125 and +0.125 pixels away from the screen centre
				if Object.ScreenXPos > -0x2000
					if Object.ScreenXPos < 0x2000

						if object[2].value13 <= 0
							object[2].yvel = 0x2A000
							object[2].state = 16
							PlayMusic(4)
							PlaySfx(SfxName[Thud], 0)
							
							object.state++
						end if

					end if
				end if
			end if
		end if

break
case SLENDERBOSSBUILDUP
	object.timer++
	if object.timer == 480
		object.timer = 0
		Object.XVelocity = 0
		Object.ZVelocity = 0
		Object.Shield = 1
		PlaySfx(SfxName[Blue Shield], 0)
		NextAttack = 0
		object.state++
	end if
break
case SLENDERBOSS_MOVE
	//fight

	Object.XPos += Object.XVelocity
	Object.ZPos += Object.ZVelocity

	// Long list of checks for the hitbox detection

	if stage.playerlistpos >= 2
		if stage.playerlistpos == 5
			temp2 = 100
		else
			temp2 = 150
		end if
		Object.SpawnTimer++
		if object.SpawnTimer == temp2
			PlaySfx(SfxName[Blast], 0)
			CreateTempObject(TypeName[Plasma], 0, object.xpos, Object.Value0)
			object.SpawnTimer = 0
		end if
	end if

	
	// The Player has to be more than 54 pixels off the ground, but lower than 122 pixels towards the sky
	foreach (TypeName[Sonic], arrayPos2, ALL_ENTITIES)	

		//if player isnt hurt
		if object[2].value13 == 0
			if Slender.Health <= Slender.HalfHP
					//now im mad

					switch stage.playerlistpos
					case 0	//norm
						Player.SpeedAdjust1 = 0x3800
						Player.SpeedAdjustCap = 0x24000
						Player.SpeedAdjust3 = 0x2000
					break
					case 1	//easy
						Player.SpeedAdjust1 = 0x3200
						Player.SpeedAdjustCap = 0x22000
						Player.SpeedAdjust3 = 0x1800
					break
					case 2	//hard
						Player.SpeedAdjust1 = 0x4000
						Player.SpeedAdjustCap = 0x26000
						Player.SpeedAdjust3 = 0x2000
					break			
					case 5
						Player.SpeedAdjust1 = 0x4200
						Player.SpeedAdjustCap = 0x30000
						Player.SpeedAdjust3 = 0x2000
					break				
					end switch

					CheckGreater(object.xpos, object[arrayPos2].xpos)
					temp0 = checkResult
					if temp0 == 1		//right
						if Object.XVelocity > 0
							Object.XVelocity -= Player.SpeedAdjust1	//right
							if Object.XVelocity > Player.SpeedAdjustCap
							Object.XVelocity = Player.SpeedAdjustCap
							end if
						else
							Object.XVelocity -= Player.SpeedAdjust3	//left?? i have no clue
							if Object.XVelocity > Player.SpeedAdjustCap
							Object.XVelocity = Player.SpeedAdjustCap
							end if			
						end if
					else	//left
						if Object.XVelocity < 0
							Object.XVelocity += Player.SpeedAdjust1
							if Object.XVelocity > Player.SpeedAdjustCap
							Object.XVelocity = Player.SpeedAdjustCap
							end if		
						else
							Object.XVelocity += Player.SpeedAdjust3
							if Object.XVelocity > Player.SpeedAdjustCap
							Object.XVelocity = Player.SpeedAdjustCap
							end if								
						end if
					end if

					CheckGreater(object.ZPos, object[arrayPos2].Value0)
					temp0 = checkResult
					if temp0 == 1		//right
						if Object.ZVelocity > 0
							Object.ZVelocity -= Player.SpeedAdjust1	//right
							if Object.ZVelocity > Player.SpeedAdjustCap
							Object.ZVelocity = Player.SpeedAdjustCap
							end if
						else
							Object.ZVelocity -= Player.SpeedAdjust3	//left?? i have no clue
							if Object.ZVelocity > Player.SpeedAdjustCap
							Object.ZVelocity = Player.SpeedAdjustCap
							end if			
						end if
					else	//left
						if Object.ZVelocity < 0
							Object.ZVelocity += Player.SpeedAdjust1
							if Object.ZVelocity > Player.SpeedAdjustCap
							Object.ZVelocity = Player.SpeedAdjustCap
							end if		
						else
							Object.ZVelocity += Player.SpeedAdjust3
							if Object.ZVelocity > Player.SpeedAdjustCap
							Object.ZVelocity = Player.SpeedAdjustCap
							end if								
						end if
					end if
			else	//HP greater then half health, normal speed basically
			
				switch stage.playerlistpos
				case 0	//norm
					Player.SpeedAdjust1 = 0x3000
					Player.SpeedAdjustCap = 0x25000
					Player.SpeedAdjust3 = 0x1500
				break
				case 1	//easy
					Player.SpeedAdjust1 = 0x2800
					Player.SpeedAdjustCap = 0x22000
					Player.SpeedAdjust3 = 0x1600
				break
				case 2	//hard
					Player.SpeedAdjust1 = 0x3200
					Player.SpeedAdjustCap = 0x26000
					Player.SpeedAdjust3 = 0x1400
				break			
				case 5
					Player.SpeedAdjust1 = 0x3400
					Player.SpeedAdjustCap = 0x30000
					Player.SpeedAdjust3 = 0x1400
				break				
				end switch


				CheckGreater(object.xpos, object[arrayPos2].xpos)
				temp0 = checkResult
				if temp0 == 1		//right
					if Object.XVelocity > 0
						Object.XVelocity -= Player.SpeedAdjust1	//right
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if
					else
						Object.XVelocity -= Player.SpeedAdjust3	//left?? i have no clue
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if			
					end if
				else	//left
					if Object.XVelocity < 0
						Object.XVelocity += Player.SpeedAdjust1
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if		
					else
						Object.XVelocity += Player.SpeedAdjust3
						if Object.XVelocity > Player.SpeedAdjustCap
						Object.XVelocity = Player.SpeedAdjustCap
						end if								
					end if
				end if

				CheckGreater(object.ZPos, object[arrayPos2].Value0)
				temp0 = checkResult
				if temp0 == 1		//right
					if Object.ZVelocity > 0
						Object.ZVelocity -= Player.SpeedAdjust1	//right
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if
					else
						Object.ZVelocity -= Player.SpeedAdjust3	//left?? i have no clue
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if			
					end if
				else	//left
					if Object.ZVelocity < 0
						Object.ZVelocity += Player.SpeedAdjust1
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if		
					else
						Object.ZVelocity += Player.SpeedAdjust3
						if Object.ZVelocity > Player.SpeedAdjustCap
						Object.ZVelocity = Player.SpeedAdjustCap
						end if								
					end if
				end if
			end if	
		else
			Object.ZVelocity = 0
			Object.XVelocity = 0
		end if

		
		// The UFO has to be within the 2100 range from the player, who's at a depth of 0x5800 normally
		if Object.ScreenDepth < 0x8C8
			if Object.ScreenDepth > 0x094

				// The UFO has to be between -0.125 and +0.125 pixels away from the screen centre
				if Object.ScreenXPos > -0x2000
					if Object.ScreenXPos < 0x2000

						if object[2].value13 <= 0
							object[2].state = 14
						end if

					end if
				end if
			end if
		end if
	next

	Object.Timer++

	if object.timer == 1000
		object.SpawnTimer = 0
		Object.Timer = 0
		Object.XVelocity = 0
		Object.ZVelocity = 0	
		Object.Shield = 2	
		switch NextAttack
			case 0
				object.state++
			break
			case 1
				object.state = 7
			break
		end switch
	end if
break
case SLENDERBOSS_CREATEPLASMA	//summon plasma

	Object.XVelocity = 0
	Object.ZVelocity = 0

	object.timer++
	//spawn rate
	switch stage.playerlistpos
	case 0
		if Slender.Health <= Slender.HalfHP
			temp0 = 50
		else
			temp0 = 75
		end if
	break
	case 1
		temp0 = 75
	break	
	case 2
		if Slender.Health <= Slender.HalfHP
			temp0 = 45
		else
			temp0 = 65
		end if
	break	
	case 5
		if Slender.Health <= Slender.HalfHP
			temp0 = 40
		else
			temp0 = 60
		end if
	break		
	end switch
	if object.timer == temp0
		PlaySfx(SfxName[Blast], 0)
		CreateTempObject(TypeName[Plasma], 0, object.xpos, Object.Value0)
		object.timer = 0
	end if


	Object.BoredTimer++
	if Object.BoredTimer == 800
		Object.Shield = 1
		Object.BoredTimer = 0
		NextAttack = 0
		object.timer = 0
		object.state = 4	
	end if



	// The Player has to be more than 54 pixels off the ground, but lower than 122 pixels towards the sky
	foreach (TypeName[Sonic], arrayPos2, ALL_ENTITIES)	
		// The UFO has to be within the 2100 range from the player, who's at a depth of 0x5800 normally
		if Object.ScreenDepth < 0x8C8
			if Object.ScreenDepth > 0x094

				// The UFO has to be between -0.125 and +0.125 pixels away from the screen centre
				if Object.ScreenXPos > -0x2000
					if Object.ScreenXPos < 0x2000
						object[2].yvel = 0x2A000
						object[2].state = 16
						PlaySfx(SfxName[SlenderHit], 0)
						PlaySfx(SfxName[Thud], 0)
						object.timer = 0
						Object.Shield = 1
						Object.BoredTimer = 0
						Slender.Health -= 1
						NextAttack = 1
						if Slender.Health == 1
							PlayMusic(9)
						end if
						object.state++
					end if
				end if
			end if
		end if
	next
break
case SLENDERBOSS_HITRECOVER	//recover
	object.timer++
	if object.timer == 100
		object.timer = 0
		object.state = 4
	end if
break
case SLENDERBOSS_LIGHTING	//lighitnbg


	Object.BoredTimer++
	if Object.BoredTimer == 800
		Object.Shield = 1
		Object.BoredTimer = 0
		NextAttack = 0
		object.timer = 0
		object.state = 4	
	end if

	// The Player has to be more than 54 pixels off the ground, but lower than 122 pixels towards the sky
	foreach (TypeName[Sonic], arrayPos2, ALL_ENTITIES)	
	
		// The UFO has to be within the 2100 range from the player, who's at a depth of 0x5800 normally
		if Object.ScreenDepth < 0x8C8
			if Object.ScreenDepth > 0x094

				// The UFO has to be between -0.125 and +0.125 pixels away from the screen centre
				if Object.ScreenXPos > -0x2000
					if Object.ScreenXPos < 0x2000
						object[2].yvel = 0x2A000
						object[2].state = 16
						PlaySfx(SfxName[SlenderHit], 0)
						PlaySfx(SfxName[Thud], 0)
						object.timer = 0
						Object.Shield = 1
						Slender.Health--
						Object.BoredTimer = 0
						NextAttack = 0
						object.state = 6
					end if
				end if
			end if
		end if
	next

	object.timer++

	//summon faster if lower hp
	switch stage.playerlistpos
	case 0
		if Slender.Health <= Slender.HalfHP
			temp0 = 50
		else
			temp0 = 75
		end if
	break
	case 1
		temp0 = 75
	break	
	case 2
		if Slender.Health <= Slender.HalfHP
			temp0 = 45
		else
			temp0 = 65
		end if
	break	
	case 5
		if Slender.Health <= Slender.HalfHP
			temp0 = 40
		else
			temp0 = 60
		end if
	break		
	end switch
	if object.timer == temp0
		PlaySfx(SfxName[Blast], 0)
		CreateTempObject(TypeName[Thunder], 0, object[2].xpos, Object[2].Value0)
		if Slender.Health <= Slender.HalfHP
			CreateTempObject(TypeName[Plasma], 0, object.xpos, Object.Value0)
		end if
		object.timer = 0
	end if
	
break
case SLENDERBOSS_DEFEATED
	Object.Shield = 0
	BossActive = 0

	Object.XVelocity = 0
	Object.ZVelocity = 0	

	object.state = 21
break
case SLENDERBOSS_DEFEATWAIT
	object.timer++
	Object.XVelocity = 0
	Object.ZVelocity = 0	

	if object.timer == 50
		object.state++
		object.timer = 0
	end if
break
case SLENDERBOSS_WAITFORINPUT
	if Delta_Activate == 0
		if SlenderSpared == 0	//killed
			// The UFO has to be within the 2100 range from the player, who's at a depth of 0x5800 normally
			if Object.ScreenDepth < 0x18C8
				if Object.ScreenDepth > 0x1094

					// The UFO has to be between -0.125 and +0.125 pixels away from the screen centre
					if Object.ScreenXPos > -0x2000
						if Object.ScreenXPos < 0x2000

							if object[2].value13 <= 0
								object[2].yvel = 0x2A000
								object[2].state = 16
							
								PlaySfx(SfxName[Thud], 0)
								
								object.state++
							end if

						end if
					end if
				end if
			end if	
		else 	//he chill
		
		end if
	end if
break
case SLENDERBOSS_DYING
	object.rotation += 45
	object.timer++
	if object.timer == 600
		PlaySfx(SfxName[Thud], 0)
		object.state++
	end if
break
case 24
	object.type = TypeName[Blank Object]
break
case 25
	if object[8].state == 12
		object.type = TypeName[Blank Object]
	end if
break
end switch

if object.state < 20
	if Slender.Health == 0
		StopMusic()	
		object.timer = 0
		object.boredtimer = 0 
		object.state = 20
	end if
end if


end event


event ObjectDraw
if object.state == 0
	CheckEqual(inputdown[2].buttonY,1)
	temp3 = checkResult
	CheckEqual(ThunderActive,1)
	temp3 |= checkResult
	if temp3 == 1
		if object.state != 1
			if Object.ScreenDepth > 256 // Don't draw if the UFO is too close to the screen
				
				// Do some maths to find the position & scale the UFO should be at
				
				Object.Scale = 0xC00000
				Object.Scale /= Object.ScreenDepth
				
				temp0 = 768
				temp0 -= Object.Scale
				temp0 /= 6
				
				temp1 = Object.ScreenDepth
				temp1 >>= 12
				
				if temp0 > 0
					Object.Scale += temp0
					Object.Scale -= temp1
				end if
				
				temp0 = Object.ScreenXPos
				temp0 *= 192
				temp0 /= Object.ScreenDepth
				temp0 += Screen.xcenter
				
				temp1 = TileLayer[0].YPos
				temp1 >>= 8
				temp1 -= 0x2000
				temp1 *= 96
				temp1 /= Object.ScreenDepth
				temp1 += 128
				
				// Draw the UFO now
				DrawSpriteScreenFX(0, FX_ROTOZOOM, temp0, temp1)
				
				// Find the ground position
				temp1 = TileLayer[0].YPos
				temp1 >>= 8
				temp1 *= 96
				temp1 /= Object.ScreenDepth
				temp1 += 128
				
				// Draw the shadow on the ground
				DrawSpriteScreenFX(3, FX_SCALE, temp0, temp1)
				
				switch Object.Shield
				case 1
					//grey
					DrawSpriteScreenFX(1, FX_SCALE, temp0, temp1)
				break
				case 2	//bluey
				//nv
				break

				end switch
			end if
		end if
	end if
else

	if object.state != 1
		if Object.ScreenDepth > 256 // Don't draw if the UFO is too close to the screen
			
			// Do some maths to find the position & scale the UFO should be at
			
			Object.Scale = 0xC00000
			Object.Scale /= Object.ScreenDepth
			
			temp0 = 768
			temp0 -= Object.Scale
			temp0 /= 6
			
			temp1 = Object.ScreenDepth
			temp1 >>= 12
			
			if temp0 > 0
				Object.Scale += temp0
				Object.Scale -= temp1
			end if
			
			temp0 = Object.ScreenXPos
			temp0 *= 192
			temp0 /= Object.ScreenDepth
			temp0 += Screen.xcenter
			
			temp1 = TileLayer[0].YPos
			temp1 >>= 8
			temp1 -= 0x2000
			temp1 *= 96
			temp1 /= Object.ScreenDepth
			temp1 += 128
			
			// Draw the UFO now
			DrawSpriteScreenFX(0, FX_ROTOZOOM, temp0, temp1)
			
			// Find the ground position
			temp1 = TileLayer[0].YPos
			temp1 >>= 8
			temp1 *= 96
			temp1 /= Object.ScreenDepth
			temp1 += 128
			
			// Draw the shadow on the ground
			DrawSpriteScreenFX(3, FX_SCALE, temp0, temp1)
			
			switch Object.Shield
			case 1
				//grey
				DrawSpriteScreenFX(1, FX_SCALE, temp0, temp1)
			break
			case 2	//bluey
			//nv
			break

			end switch
		end if
	end if

end if
end event


event ObjectStartup
	
	LoadSpriteSheet("3D_Test/Objects.gif")
	
	// UFO Frames
	
	// 0 - SLENDERMAN!!
	SpriteFrame(-30, -82, 63, 112, 339, 1)
	
	// 1 - Blue Sheild
	SpriteFrame(-46, -102, 90, 96, 671, 211)
	
	// 2 - Extra Time Variant
	SpriteFrame(-46, -102, 90, 96, 671, 114)
	
	// 3 - UFO Shadow Frame
	SpriteFrame(-40, -8, 80, 16, 1, 117)

	
	// Place a Sonic object into reserved object slot 2 and initialise its values
	Object[6].Type = TypeName[UFO]
	
	// Make Sonic always active
	Object[6].Priority = PRIORITY_ACTIVE
	
// private alias Object.Value11 : Slender.Health
// private alias Object.Value12 : Slender.HalfHP
	
	//Setup HP
	switch stage.playerlistpos
	case 0
	case 2
		Object[6].Value11 = 6
		temp0 = Object[6].Value11
		temp0 /= 2
		Object[6].Value12 = temp0
	break
	case 1
		Object[6].Value11 = 4
		temp0 = Object[6].Value11
		temp0 /= 2
		Object[6].Value12 = temp0
	break	
	case 5
		Object[6].Value11 = 8
		temp0 = Object[6].Value11
		temp0 /= 2
		Object[6].Value12 = temp0
	break	
	end switch	

	// Cycle through all UFO objects in the scene and set them up
	ArrayPos0 = 32
	while ArrayPos0 < 1056
		if Object[ArrayPos0].Type == TypeName[UFO]
			// Due to the difference between editor and game, turn YPos into ZPos here
			Object[6].ZPos = Object[ArrayPos0].YPos
			ResetObjectEntity(ArrayPos0, TypeName[Blank Object], 0, 0, 0)
		end if
		ArrayPos0++
	loop
	
end event


// ========================
// Editor events
// ========================

event RSDKEdit
	if Editor.ReturnVariable == true
		switch Editor.VariableID
		case EDIT_VAR_PROPVAL // Property Value
			CheckResult = Object.PropertyValue
			break
		case 0 // Contents
			CheckResult = Object.PropertyValue
			break
		end switch
	else
		switch Editor.VariableID
		case EDIT_VAR_PROPVAL // Property Value
			Object.PropertyValue = Editor.VariableValue
			break
		case 0 // Contents
			Object.PropertyValue = Editor.VariableValue
			break
		end switch
	end if
end event


event RSDKDraw
	DrawSprite(Object.PropertyValue)
	
	if Editor.ShowGizmos == true
		// Draw arrows to show the network of UFO nodes
		
		Editor.DrawingOverlay = true
		
		ArrayPos1 = Object.entityPos
		ArrayPos0 = Object.entityPos
		ArrayPos0++
		
		// TODO: change this to "UFO Node" once GetObjectType works with spaces
		GetObjectType(temp0, "UFONode")
		
		while Object[ArrayPos0].Type == temp0
			DrawArrow(Object[ArrayPos1].XPos, Object[ArrayPos1].ZPos, Object[ArrayPos0].XPos, Object[ArrayPos0].ZPos, 255, 255, 0)
			ArrayPos0++
			ArrayPos1++
		loop
		
		ArrayPos0 = Object.entityPos
		ArrayPos0++
		if ArrayPos1 != Object.entityPos
			DrawArrow(Object[ArrayPos1].XPos, Object[ArrayPos1].ZPos, Object[ArrayPos0].XPos, Object[ArrayPos0].ZPos, 255, 255, 0)
		end if
		
		Editor.DrawingOverlay = false
	end if
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(-40, -28, 80, 56, 1, 1)
	SpriteFrame(-40, -28, 80, 56, 82, 1)
	SpriteFrame(-40, -28, 80, 56, 163, 1)

	AddEditorVariable("Contents")
	SetActiveVariable("Contents")
	AddEnumVariable("10 Rings", UFO_CONTENTS_RINGS)
	AddEnumVariable("Speed Shoes", UFO_CONTENTS_SPEEDSHOES)
	AddEnumVariable("Extra Time", UFO_CONTENTS_TIME)
end event
